package main

import (
	"fmt"
	"github.com/garyburd/redigo/redis"
)

func main() {

	// 连接redis数据库
	conn, err := redis.Dial("tcp", "192.168.0.35:6379")

	if err != nil {
		fmt.Printf("Redis connect error=%v\n", err)
		return
	}

	// 关闭连接
	defer conn.Close()

	fmt.Printf("Redis connection success")

	// Set操作
	_, err = conn.Do("set", "username", "administrator")

	if err != nil {
		fmt.Printf("Redis set error=%v\n", err)
	}

	// Get操作
	value, err := redis.String(conn.Do("get", "username"))

	if err != nil {
		fmt.Printf("Redis get error=%v\n", err)
	} else {
		fmt.Printf("Redis get username=%v\n", value)
	}
}
